    subroutine ccsdt_calcaaa_2(ie, t1_i, t1_j, t1_k, &
                  t2_ij, t2_jk, t2_ki, t22_i, t22_j, t22_k, & 
                  iabci_i, iabci_j, iabci_k,                 &
                  iijka_ij, iijka_jk, iijka_ki,              & 
                  iabij_ij, iabij_jk, iabij_ki,                & 
                  tmpv, tmpv2, tmpv3, tmpe,  icore,              &
                  irrepi, irrepj, irrepk, i, j, k,               &
                  ioffvvvo, ioffvvoo2, ioffvvoo, ioffvooo,       &
                  ioffvo, e4t, e5st, vrta, vrtb, popa, popb, iop)
      use omp_lib
      use mod_symm, only: dirprd
      use mod_orbit, only: noa, zorb
      use mod_iop, only: totgpu
      use mod_t
      implicit none 
!
      integer, intent(in):: vrta(8), vrtb(8), popa(8), popb(8)
      integer, intent(in):: ioffvvvo(noa,8), ioffvvoo2(noa,8)
      integer, intent(in):: ioffvo(noa,8), iop
      integer, intent(in):: ioffvvoo(noa,noa,8,8)
      integer, intent(in):: ioffvooo(noa,noa,8,8) 
      real*8, intent(inout) :: e4t, e5st
      real*8, intent(inout) :: icore(*), ie(*) 
      real*8, intent(in) :: t1_i(*), t1_j(*), t1_k(*) 
      real*8, intent(in) :: t2_ij(*), t2_jk(*), t2_ki(*)
      real*8, intent(in) :: t22_i(*), t22_j(*), t22_k(*) 
      real*8, intent(in) :: iabci_i(*), iabci_j(*), iabci_k(*) 
      real*8, intent(in) :: iijka_ij(*), iijka_jk(*), iijka_ki(*)
      real*8, intent(in) :: iabij_ij(*), iabij_jk(*), iabij_ki(*)
!
      real*8, intent(out) :: tmpe(*), tmpv(*),tmpv2(*),tmpv3(*) 
!
      integer irrepij, irrepjk, irrepki, irrepabc
      integer i,j,k,a,b,c,e,m, idx,idx2
      integer irrepi, irrepj, irrepk, numi, numj, numk, numab
      integer numa, numb, numc, irrepa, irrepb, irrepc
      integer irrepab, irrepbc, irrepca, numbc, numca
      integer ioff1, ioff2
      integer idxi, idxj, idxk, idxa, idxb, idxc
      integer nsize, istartij, ioff21, ioff22, ioff23 
      integer i0, i1, i2, i3 
      double precision eatmp, vtmp, vtmp2
      double precision tgemmc, tsstgenc, tdoc, tt2, tt1, rt2, rt1
      double precision tgemmr, tsstgenr, tdor
      real*8, allocatable :: tmptest(:)
!      
      integer, external :: irpdso, idsymsoc, isymoffso, idsymabc
      real*8, external :: nrm2so, ddot, dotso, dotso2
!
      allocate(tmptest(10))
      irrepij = dirprd(irrepi, irrepj)
      irrepjk = dirprd(irrepj, irrepk) 
      irrepki = dirprd(irrepk, irrepi) 
      irrepabc = dirprd(irrepij, irrepk)
      i0 = 1 
      i1 = i0 + idsymsoc(irrepabc, vrta, vrta, 1, vrta, zorb, 1) 
      i2 = i1 + idsymsoc(irrepabc, vrta, vrta, 1, vrta, zorb, 1) 
      i3 = i2 + idsymsoc(irrepabc, vrta, vrta, 1, vrta, zorb, 1) 
!---IABCIAA(b,c,e,i)*T2(a,e,j,k)
      call cpu_time(tt1); call walltimeso(rt1)
            ioff1 = ioffvvvo(i, irrepi)  
            ioff2 = ioffvvoo(j,k,irrepj, irrepk)
!            write(6,*)'irrepi, irrepjk', irrepi, irrepjk
            call VpqmnVrsmn_to_Vpqrs(iabci_i, t2_jk,&
                irrepi, irrepjk, vrta, zorb, 1, vrta, vrta, 0, &
                vrta, zorb, 1, tmpv2, irrepabc, 1.d0, 0.d0)
!        nsize = idsymsoc(irrepi, vrta, vrta, 0, vrta, zorb, 1)
!        write(6,'(A, 3I4, F18.12)')'iabci_i', i, j, k, nrm2so(nsize, iabci_i, 1)
!        nsize = idsymsoc(irrepjk, vrta, zorb, 1, vrta, zorb, 1)
!        write(6,'(A, 3I4, F18.12)')'t2_jk  ', i, j, k, nrm2so(nsize, t2_jk, 1)
!        nsize = idsymsoc(irrepabc, vrta, vrta, 0, vrta, zorb, 1)
!        write(6,'(A, 3I4, F18.12)')'tmpv2  ', i, j, k, nrm2so(nsize, tmpv2, 1)
!---IABCIAA(b,c,e,j)*T2(a,e,k,i)
            ioff1 = ioffvvvo(j, irrepj)  
            ioff2 = ioffvvoo(k,i,irrepk, irrepi)
            call VpqmnVrsmn_to_Vpqrs(iabci_j,t2_ki,&
                irrepj, irrepki, vrta, zorb, 1, vrta, vrta, 0, &
                vrta, zorb, 1 , tmpv2, irrepabc, 1.d0, 1.d0) 
!---IABCIAA(b,c,e,k)*T2(a,e,i,j)
            ioff1 = ioffvvvo(k, irrepk)  
            ioff2 = ioffvvoo(i,j,irrepi, irrepj)
            call VpqmnVrsmn_to_Vpqrs(iabci_k,t2_ij,&
                irrepk, irrepij, vrta, zorb, 1, vrta, vrta, 0, &
                vrta, zorb, 1 , tmpv2, irrepabc, 1.d0, 1.d0) 
!---T2AA(A,B,M,I)*IIJKAAA(M,C,J,K)
            ioff1 = ioffvvoo2(i, irrepi)  
            ioff2 = ioffvooo(j,k,irrepj, irrepk)
            call VpqmnVmnrs_to_Vpqrs(t22_i,iijka_jk,&
                irrepi, irrepjk, popa, zorb, 1, vrta, vrta, 0, &
                vrta, zorb, 1 , tmpv2, irrepabc, 1.d0, 1.d0) 
!---T2AA(A,B,M,J)*IIJKAAA(M,C,K,I)
            ioff1 = ioffvvoo2(j, irrepj)  
            ioff2 = ioffvooo(k,i,irrepk, irrepi)
            call VpqmnVmnrs_to_Vpqrs(t22_j,iijka_ki,&
                irrepj, irrepki, popa, zorb, 1, vrta, vrta, 0, &
                vrta, zorb, 1 , tmpv2, irrepabc, 1.d0, 1.d0) 
!---T2AA(A,B,M,K)*IIJKAAA(M,C,I,J)
            ioff1 = ioffvvoo2(k, irrepk)
            ioff2 = ioffvooo(i,j,irrepi, irrepj)
            call VpqmnVmnrs_to_Vpqrs(t22_k,iijka_ij,&
                irrepk, irrepij, popa, zorb, 1, vrta, vrta, 0,&
                vrta, zorb, 1 , tmpv2, irrepabc, 1.d0, 1.d0)
           if(totgpu==1) then 
           call myicopy_c(tmpv2, tmptest, 1)
           endif
      call cpu_time(tt2); call walltimeso(rt2)
            tvpq = tvpq + rt2-rt1
!---expand tmp(a<b, c) to tmp(a,b,c)
      call cpu_time(tt1); call walltimeso(rt1)
            call iexpso(tmpv2, tmpv, vrta, vrta, 0, 1, vrta, zorb, 1, 0, irrepabc) 
!---tmp(a<b<c) = tmp(a,b,c)+tmp(b,c,a)+tmp(c,a,b)
            call symabc(tmpv, tmpv3, vrta, irrepabc)
!           
           if(totgpu==1) then 
           call myicopy_c(tmpv2, tmptest, 1)
           endif
      call cpu_time(tt2); call walltimeso(rt2)
            tgen = tgen + rt2-rt1
!            
!---IABIJAA(b,c,j,k)*T1AA(a,i)
      call cpu_time(tt1); call walltimeso(rt1)
            ioff1 = ioffvvoo(j,k, irrepj, irrepk) 
            ioff2 = ioffvo(i,irrepi)
            call VpqmnVrsmn_to_Vpqrs(iabij_jk,t1_i, &
               irrepjk, irrepi, zorb, zorb, 1, vrta, vrta, 1, &
               vrta, zorb, 1, tmpv2, irrepabc, 1.d0, 0.d0)
!---IABIJAA(b,c,k,i)*T1AA(a,j)
            ioff1 = ioffvvoo(k,i, irrepk, irrepi) 
            ioff2 = ioffvo(j,irrepj)
            call VpqmnVrsmn_to_Vpqrs(iabij_ki,t1_j, &
               irrepki, irrepj, zorb, zorb, 1, vrta, vrta, 1, &
               vrta, zorb, 1, tmpv2, irrepabc, 1.d0, 1.d0)
!---IABIJAA(b,c,i,j)*T1AA(a,k)
            ioff1 = ioffvvoo(i,j, irrepi, irrepj) 
            ioff2 = ioffvo(k,irrepk)
            call VpqmnVrsmn_to_Vpqrs(iabij_ij,t1_k, &
               irrepij, irrepk, zorb, zorb, 1, vrta, vrta, 1, &
               vrta, zorb, 1, tmpv2, irrepabc, 1.d0, 1.d0)
           if(totgpu==1) then 
           call myicopy_c(tmpv2, tmptest, 1)
           endif
      call cpu_time(tt2); call walltimeso(rt2)
            tvpq = tvpq + rt2-rt1
!---tmp(a,b,c) = tmp(a,b,c)+tmp(b,c,a)+tmp(c,a,b)
      call cpu_time(tt1); call walltimeso(rt1)
            call symabc(tmpv2, tmpv, vrta, irrepabc)
!---calc Dabc(a,b,c) =V1abc/(ea+eb+ec-ei-ej-ek)
           if(totgpu==1) then 
           call myicopy_c(tmpv2, tmptest, 1)
           endif
      call cpu_time(tt2); call walltimeso(rt2)
            tgen = tgen + rt2-rt1
!
      call cpu_time(tt1); call walltimeso(rt1)
         nsize = idsymabc(irrepabc, vrta)
!         write(6,'(A, 3I4, F18.12)')'tmpv2', i, j, k, nrm2so(nsize, tmpv2, 1)
!         write(6,'(A, 3I4, F18.12)')'tmpv3', i, j, k, nrm2so(nsize, tmpv3, 1)
          call calceaaa(ie, tmpv2, tmpv3, i, j, k, & 
                      irrepi, irrepj, irrepk, vrta, popa)
          nsize = idsymabc(irrepabc, vrta)
!         write(6,'(A, 3I4, F18.12)')'tmpv2_2', i, j, k, nrm2so(nsize, tmpv2, 1)
!         write(6,'(A, 3I4, F18.12)')'tmpv3_2', i, j, k, nrm2so(nsize, tmpv3, 1)
!---Energy = (V1abc + v2abc)*V1abc/Dabc
          e4t  = e4t + dotso(nsize, tmpv2, 1, tmpv3, 1)
          e5st = e5st + dotso(nsize, tmpv2, 1, tmpv, 1)
           if(totgpu==1) then 
           call myicopy_c(tmpv2, tmptest, 1)
           endif
      call cpu_time(tt2); call walltimeso(rt2)
          ttmpe = ttmpe + rt2-rt1
      call cpu_time(tt1); call walltimeso(rt1)
          e4ttest  = e4ttest + dotso2(nsize, tmpv2, 1, tmpv3, 1)
          e5sttest = e5sttest + dotso2(nsize, tmpv2, 1, tmpv, 1)
      call cpu_time(tt2); call walltimeso(rt2)
          ttmpe2 = ttmpe2 + rt2-rt1
!          write(6,'(A, 3I4, 2F18.8)')'e4t', i,j,k,e4t, e5st
      return
      end











      
